package com.betterjr.modules.order.dubbo;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.betterjr.common.web.AjaxObject;
import com.betterjr.modules.order.IScfOrderService;
import com.betterjr.modules.order.entity.ScfOrder;
import com.betterjr.modules.order.entity.ScfOrderDO;
import com.betterjr.modules.order.service.ScfOrderDOService;
import com.betterjr.modules.order.service.ScfOrderService;
import com.betterjr.modules.rule.service.RuleServiceDubboFilterInvoker;

@Service(interfaceClass = IScfOrderService.class)
public class ScfOrderDubboService implements IScfOrderService {

    @Autowired
    private ScfOrderService scfOrderService;

    @Autowired
    private ScfOrderDOService orderService;

    @Override
    public String webSaveModifyOrder(final Map<String, Object> anMap, final Long anId, final String anFileList,
            final String anOtherFileList) {
        ScfOrder anOrder = (ScfOrder) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("订单信息编辑成功", scfOrderService.saveModifyOrder(anOrder, anId, anFileList, anOtherFileList))
                .toJson();
    }

    @Override
    public String webSaveModifyOrderDO(final Map<String, Object> anMap, final String anFileList,
            final boolean confirmFlag) {
        ScfOrderDO anOrder = (ScfOrderDO) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("订单信息编辑成功", orderService.saveModifyOrder(anOrder, anFileList, confirmFlag)).toJson();
    }

    @Override
    public String webQueryOrder(final Map<String, Object> anMap, final String anIsOnlyNormal, final String anFlag,
            final int anPageNum, final int anPageSize) {
        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOkWithPage("订单信息查询成功",
                        scfOrderService.queryOrder(anQueryConditionMap, anIsOnlyNormal, anFlag, anPageNum, anPageSize))
                .toJson();
    }

    @Override
    public String webQueryOrderDO(final Map<String, Object> anMap, final String anIsOnlyNormal, final String anFlag,
            final int anPageNum, final int anPageSize) {
        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOkWithPage("订单信息查询成功",
                        orderService.queryOrder(anQueryConditionMap, anIsOnlyNormal, anFlag, anPageNum, anPageSize))
                .toJson();
    }

    @Override
    public String webQueryIneffectiveOrderDO(final Map<String, Object> anMap, final String anIsOnlyNormal,
            final String anFlag, final int anPageNum, final int anPageSize, final boolean anIsAudit) {
        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOkWithPage("订单信息查询成功", orderService.queryIneffectiveOrder(anQueryConditionMap,
                anIsOnlyNormal, anFlag, anPageNum, anPageSize, anIsAudit)).toJson();

    }

    @Override
    public String webQueryEffectiveOrderDO(final Map<String, Object> anMap, final String anIsOnlyNormal,
            final String anFlag, final int anPageNum, final int anPageSize, final boolean anIsCust) {
        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOkWithPage("订单信息查询成功", orderService.queryEffectiveOrder(anQueryConditionMap,
                anIsOnlyNormal, anFlag, anPageNum, anPageSize, anIsCust)).toJson();
    }

    @Override
    public String webFindOrderDetailsById(final Long anId) {
        return AjaxObject.newOk("订单信息查询成功", scfOrderService.findOrderDetailsById(anId)).toJson();
    }

    @Override
    public String webFindOrderList(final Map<String, Object> anMap, final String anIsOnlyNormal) {
        Map<String, Object> queryMap = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("订单信息查询成功", scfOrderService.findOrderList(queryMap, anIsOnlyNormal)).toJson();
    }

    @Override
    public String webFindInfoListByRequest(final String anRequestNo, final String anRequestType) {
        return AjaxObject.newOk("订单信息查询成功", scfOrderService.findInfoListByRequest(anRequestNo, anRequestType)).toJson();
    }

    @Override
    public String webAddOrder(final Map<String, Object> anMap, final String anFileList, final String anOtherFileList) {
        ScfOrder anOrder = (ScfOrder) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("订单信息新增成功", scfOrderService.addOrder(anOrder, anFileList, anOtherFileList)).toJson();
    }

    @Override
    public String webAddOrderDO(final Map<String, Object> anMap, final String anFileList, final boolean confirmFlag) {
        ScfOrderDO anOrder = (ScfOrderDO) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("订单信息新增成功", orderService.addOrder(anOrder, anFileList, confirmFlag)).toJson();
    }

    @Override
    public String webCheckCompleteInvoice(final String anRequestType, final String anIdList) {
        return AjaxObject.newOk("检查关联发票关系成功", scfOrderService.checkCompleteInvoice(anRequestType, anIdList)).toJson();
    }

    @Override
    public String webFindRequestBaseInfoFileList(final String anRequestNo) {
        return AjaxObject.newOk("查询所有附件成功", scfOrderService.findRequestBaseInfoFileList(anRequestNo)).toJson();
    }

    @Override
    public String webCheckInfoCompleted(final String anIdList, final String anRequestType) {
        return AjaxObject.newOk("资料检查成功", scfOrderService.checkInfoCompleted(anIdList, anRequestType) ? "0" : "1")
                .toJson();
    }

    @Override
    public String webCheckAgreementStatus(final Long anAcceptBillId) {
        return AjaxObject.newOk("合同状态检查成功", scfOrderService.checkAgreementStatus(anAcceptBillId)).toJson();
    }

    @Override
    public String webFindSubjectMaster(final String anId, final String anType) {
        return AjaxObject.newOk("查询标的物", scfOrderService.getSubjectMaster(anId, anType)).toJson();
    }

    @Override
    public String webFindCoreCustNo(final String anId, final String anType) {
        return AjaxObject.newOk("查询标的物", scfOrderService.getCoreCustNoByMaster(anId, anType)).toJson();
    }

    @Override
    public String webFindRequestByInfoId(final Long anInfoId, final String anInfoType) {
        return AjaxObject.newOk("根据资料id和资料类型查询融资实体", scfOrderService.findRequestByInfoId(anInfoId, anInfoType))
                .toJson();
    }

    @Override
    public String webQueryCanAnnulOrder(final Map<String, Object> anAnMap, final String anIsOnlyNormal,
            final String anFlag, final int anPageNum, final int anPageSize) {
        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();

        return AjaxObject.newOkWithPage("订单信息查询成功",
                orderService.queryCanAnnulBill(anQueryConditionMap, anIsOnlyNormal, anFlag, anPageNum, anPageSize))
                .toJson();
    }

    @Override
    public String webSaveAnnulOrder(final String anRefNo, final String anVersion) {

        return AjaxObject.newOk("订单废止成功", orderService.saveAnnulOrder(anRefNo, anVersion)).toJson();
    }

    @Override
    public String webSaveAuditOrderByRefNoVersion(final String anRefNo, final String anVersion) {

        return AjaxObject.newOk("订单审核成功", orderService.saveAuditOrder(anRefNo, anVersion)).toJson();
    }

    @Override
    public String webQueryIneffectiveOrder(final Map<String, Object> anMap, final String anIsOnlyNormal,
            final String anFlag, final int anPageNum, final int anPageSize, final boolean anIsAudit) {
        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOkWithPage("订单查询成功", orderService.queryIneffectiveOrder(anQueryConditionMap,
                anIsOnlyNormal, anFlag, anPageNum, anPageSize, anIsAudit)).toJson();
    }

    @Override
    public String webQueryEffectiveOrder(final Map<String, Object> anMap, final String anIsOnlyNormal,
            final String anFlag, final int anPageNum, final int anPageSize, final boolean anIsCust) {
        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOkWithPage("订单查询成功", orderService.queryEffectiveOrder(anQueryConditionMap, anIsOnlyNormal,
                anFlag, anPageNum, anPageSize, anIsCust)).toJson();
    }

    @Override
    public String webfindOrderDetail(final String anRefNo, final String anVersion) {

        return AjaxObject.newOk("订单查询成功", orderService.findOrder(anRefNo, anVersion)).toJson();
    }

    @Override
    public String webQueryExportOrderRecordList(final Long anResolveFileid, final String anFlag, final int anPageNum,
            final int anPageSize) {

        return AjaxObject
                .newOkWithPage("订单信息查询成功",
                        orderService.queryExportOrderRecordList(anResolveFileid, anFlag, anPageNum, anPageSize))
                .toJson();

    }

    @Override
    public String webSaveResolveFile(final Map<String, Object> anAnMap) {

        return AjaxObject.newOk("订单解析成功", orderService.saveResolveOrderFile(anAnMap)).toJson();
    }

    @Override
    public String webSaveAuditOrderByOrderIds(final String ids) {

        return AjaxObject.newOk("订单审核成功", orderService.saveAuditOrders(ids).size()).toJson();
    }

    /** 
     * <p>Overriding Method of webQueryNotUserEffectiveOrderDO</p>  
     * <p>Description: </p> 
     * @Description: 分页查询生效，未使用订单 
     * @param anPageNum 页码
     * @param anPageSize  页面大小
     * @param anFlag    是否统计总数
     * @param anIsCust  true供应商  false核心企业
     * @return 
     * @see com.betterjr.modules.order.IScfOrderService#webQueryNotUserEffectiveOrderDO(java.util.Map, int, int, int, java.lang.Boolean) 
     * @author xuzx
     * @date 2017年11月22日 下午4:37:27 
     */
    @Override
    public String webQueryNotUserEffectiveOrderDO(final Map<String, Object> anMap, final int anPageNum,
            final int anPageSize, final int anFlag, final Boolean anIsCust) {
        return AjaxObject.newOkWithPage("分页查询生效未使用订单 成功",
                orderService.queryNotUserOrderPage(anMap, anPageNum, anPageSize, anFlag, anIsCust)).toJson();
    }

}
